package iterators;

import java.util.HashSet;
import java.util.Set;

import config.GlobalConfig;
import controlFlowGraph.CFG;
import controlFlowGraph.CFGNode;
import domains.AnalysisDomain;
import domains.AvailableExpressions;
import domains.TrulyLiveVariables;

public class RoundRobin extends FixpointIterator {

	/* (non-Javadoc)
	 * @see iterators.FixpointIterator#doIteration(controlFlowGraph.CFG)
	 */
	@Override
	public void doIteration(CFG cfg) {
		if (GlobalConfig.debug) {
			System.out.println("Start Round Robin Iteration in mode: " + 
					GlobalConfig.iterPhase);
		}
		boolean changed = true;
		while (changed) {
			changed = false;
			for (CFGNode node : cfg.getAllNodes()) {
				if (GlobalConfig.debug) {
					System.out.println("Processing node: "+ node.getId());
				}
				AnalysisDomain newVal = recompute(node);
				if (!newVal.equals(node.getAnalysisInfo())) {
					changed = true;
					node.setAnalysisInfo(newVal);
				}
			}
			if (GlobalConfig.debug) {
				for (CFGNode node : cfg.getAllNodes()) {
					System.out.println(GlobalConfig.analysis.printNode(node));
				}
			}
		}
	}

}
